
%give a binary image, im, and make it so that all the positive pixels are
%at least a length 'd' away from eachother

function [r,ind] = downsampleConnected(im,d)

[M,N] = find(im==1);
cur = 1;
while cur < length(M)
    a = M-M(cur); b = N-N(cur);
    ind = find(abs(a)<d & abs(b) < d);
    ind = ind(ind~=cur);
    ind = setdiff(1:length(M),ind);
    M = M(ind); N = N(ind);
    cur = cur + 1;
end
ind = sub2ind(size(im),M,N);
r = zeros(size(im));
r(ind) = 1;
